﻿<Page x:Class="yaTDL.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:my="clr-namespace:yaTDL"
      xmlns:core="clr-namespace:yaTDL.Core;assembly=yaTDL.Core"
      xmlns:yaTDL_Settings="clr-namespace:yaTDL.Properties"
      mc:Ignorable="d" 
      d:DesignHeight="306" d:DesignWidth="535"
	  Title="MainPage">

    <Page.Resources>
        
        <DataTemplate x:Key="ProjectListBoxItemTemplate">
            <StackPanel Orientation="Horizontal">
                <StackPanel.ToolTip>
                    <TextBlock Text="{Binding Name}"/>
                </StackPanel.ToolTip>
                <TextBlock Text="{Binding Name}" FontSize="15" FontWeight="Regular" />
            </StackPanel>
        </DataTemplate>

        <!--Searchbox Style for TextBox -->
        <Style x:Key="searchBox" TargetType="{x:Type TextBox}">
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
            <Setter Property="AllowDrop" Value="true" />
            <Setter Property="Background" Value="Transparent"></Setter>
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
            <Setter Property="FontFamily" Value="Segoe UI" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Padding" Value="8,5,3,3" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Grid>
                            <Border x:Name="BorderBase" Background="White" BorderThickness="1.4,1.4,1,1"
                            BorderBrush="Silver" CornerRadius="0" />
                            <Canvas Width="Auto" Height="Auto" Margin="0,3,21,3"  HorizontalAlignment="Right" VerticalAlignment="Stretch" Canvas.Left="0" Canvas.Top="0">
                                <Path Width="16.7566" Height="18.5" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" StrokeThickness="2.5" StrokeLineJoin="Round" Stroke="#FF808080" Fill="#FFFFFFFF" Data="M 49.1775,22.7195C 53.4483,22.7195 56.9104,26.1816 56.9104,30.4524C 56.9104,34.7231 53.4483,38.1853 49.1775,38.1853C 44.9068,38.1853 41.4446,34.7231 41.4446,30.4524C 41.4446,26.1816 44.9068,22.7195 49.1775,22.7195 Z M 39.0896,42.7195L 44.2917,36.252"/>
                            </Canvas>
                            <Label x:Name="TextPrompt" FontFamily="Segoe WP"  FontWeight="Bold" Content="{TemplateBinding Tag}" Visibility="Collapsed" Focusable="False"  Foreground="Silver"></Label>
                            <ScrollViewer Margin="0,0,25,0" x:Name="PART_ContentHost" Foreground="{DynamicResource OutsideFontColor}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsFocused" Value="False"></Condition>
                                    <Condition Property="Text" Value=""></Condition>
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter Property="Visibility" TargetName="TextPrompt" Value="Visible"></Setter>
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" Value="DimGray" />
                            </Trigger>
                            
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <my:BoolDoubleConverter x:Key="boolDoubleConverter" />
        <my:DoubleCalculator x:Key="doubleCalculator" />
        
    </Page.Resources>
    

    <Grid>
        
                                     
        <Label Visibility="{Binding Path=ProjectListViewModel.TaskListVisibility}" Height="0" Width="0" x:Name="label" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" />
        <Button Margin="0,3,0,0" Content="SETTINGS" HorizontalContentAlignment="Right" Command="{Binding ShowSettingsCommand}" FontWeight="Bold"  Style="{DynamicResource ButtonStyle_Metro}" Height="24" HorizontalAlignment="Right" Name="button1" VerticalAlignment="Top" Width="69" />


        <ListBox Height="35" Width="Auto" BorderBrush="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-1,0,0,0"  
                ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                ItemsSource="{Binding Items, ElementName=tabControl1}" SelectedItem="{Binding SelectedItem, ElementName=tabControl1, Mode=TwoWay}" 
                Style="{StaticResource ListBoxStyle_Horizontal}" ItemContainerStyle="{StaticResource ListBoxItemStyle_Pivot}" FontSize="20">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Header, StringFormat=' {0}'}"  HorizontalAlignment="Left" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


        
        <TabControl  x:Name="tabControl1" Style="{DynamicResource HeaderlessTabControl}" HorizontalAlignment="Stretch" Width="Auto" Margin="0,20,0,0" SelectionChanged="tabControl1_SelectionChanged" VerticalAlignment="Stretch">
            
            <TabItem  Header="projects" IsSelected="{Binding ElementName=tabControl1,Path=DataContext.ProjectListViewIsVisible, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding Path=ProjectListViewModel}">
                
                <Grid Width="Auto"  HorizontalAlignment="Stretch" x:Name="grid_ProjectsTaskList">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="175" MinWidth="40" MaxWidth="440" />                                                   
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*" MinWidth="195"/>                        
                    </Grid.ColumnDefinitions>


                    

                    <Border Grid.Column="0" Margin="0,25,0,0" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="{StaticResource Application_BorderBrush}" BorderThickness="0,0,1,0">
                        <Grid>
                            <StackPanel  Margin="0,0,0,-5" Height="38" VerticalAlignment="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button Command="{Binding AddProjectCommand}" x:Name="btn_addProject" ToolTip="Add Project" VerticalAlignment="Center" Width="30" Height="30" Style="{DynamicResource ButtonStyle_Metro}" FontWeight="Bold" FontSize="25" Padding="1">
                                <Viewbox HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  									<Canvas  Height="50" Width="50">
      										<Path Stroke="{Binding Foreground, ElementName=btn_addProject}" StrokeThickness="4" Data="M 25,10 L 25,40 M 10,25 L 40,25" />
      										<Ellipse Height="50" Width="50" Stretch="Fill" StrokeThickness="3" Stroke="{Binding Foreground, ElementName=btn_addProject}"/>
  									</Canvas>
  								</Viewbox>
                            </Button>
                            <!--{Binding ElementName=btn_addProject, Path=Foreground}-->
                        </StackPanel>
                        <ListBox x:Name="ListBox_Projects" Margin="1,0,1,38" Height="Auto" Width="Auto"  BorderThickness="0" Background="Transparent" SelectedItem="{Binding Path=SelectedProject, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch"
                             VerticalAlignment="Stretch" FontFamily="Segoe UI" ItemContainerStyle="{DynamicResource ListBoxItemStyle_Metro}" ItemsSource="{Binding Projects}" ItemTemplate="{DynamicResource ProjectListBoxItemTemplate}"  
                             SelectedIndex="{Binding Projectlist_SelectedIndex, Source={x:Static yaTDL_Settings:UISettings.Default}}">
                            <ListBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="{Binding Path=SelectedProject.Name}" HeaderStringFormat="Rename '{0}'" Command="{Binding EditProjectCommand}" />
                                    <MenuItem Header="{Binding Path=SelectedProject.Name}" HeaderStringFormat="Delete '{0}'" Command="{Binding DeleteProjectCommand}" />
                                </ContextMenu>
                            </ListBox.ContextMenu>
                        </ListBox>
                        </Grid>
                    </Border>
                    
                    
                    <my:TaskListControl Grid.Column="2"  DataContext="{Binding Path=TaskListViewModel}" Margin="0,0,0,-5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding ElementName=label,Path=Visibility}" />


                    <GridSplitter HorizontalAlignment="Right" Margin="-2,0,0,0" VerticalAlignment="Stretch" Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="5" Background="Transparent"/>

                </Grid>
                        
                </TabItem>
            <TabItem Header="search" DataContext="{Binding SearchViewModel}" x:Name="searchTab" IsSelected="{Binding ElementName=tabControl1,Path=DataContext.SearchViewIsVisible, UpdateSourceTrigger=PropertyChanged}">
                
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="70"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    
                    
                    <Grid Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="{Binding ElementName=button_saveSearch, Path=IsEnabled, Converter={StaticResource boolDoubleConverter}, ConverterParameter=47}" />
                        </Grid.ColumnDefinitions>

                        <TextBox Grid.Column="0" Style="{StaticResource searchBox}" Tag="SEARCH" Height="25" Width="Auto" x:Name="searchBox"  Margin="6,20,6,0" Text="{Binding SearchTerm, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                        <Button x:Name="button_saveSearch" Grid.Column="1" Width="36" Height="36" HorizontalAlignment="Right" Margin="0,14.5,6,0" VerticalAlignment="Top" Command="{Binding SaveSearchCommand}"
							HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Style="{StaticResource ButtonStyle_Metro}" ToolTip="Save Search">                     	
								<Canvas Height="36" Width="36">
									<Viewbox HorizontalAlignment="Center" VerticalAlignment="Center" Height="20" Width="20" Margin="8">
     									<Canvas Height="500" Width="500">								    
        									<Path Stroke="{Binding Foreground, ElementName=button_saveSearch}" Fill="{Binding Foreground, ElementName=button_saveSearch}" Data="M 0,0 L 425,0 L 500,75 L 500,500 L 0,500 L 0,0"/>				
											<Path Stroke="White" Path.Fill="White" Data="M 100,10 L 350,10 L 350,175 L 100,175 L 100,10"></Path>
											<Path Stroke="{Binding Foreground, ElementName=button_saveSearch}" Fill="{Binding Foreground, ElementName=button_saveSearch}" Data="M 250,30 L 325,30 L 325,155 L 250,155 L 250,30"></Path>
					    				</Canvas>
  
  									</Viewbox>
									
									<Ellipse Width="36" Height="36" Stretch="Fill" StrokeLineJoin="Round" StrokeThickness="2" Stroke="{Binding Foreground, ElementName=button_saveSearch}"/>
									
								</Canvas>
								
     												                
						</Button>
                    </Grid>
                    
                    
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="gridColumn_SavedSearches" MinWidth="125" Width="200"/>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" MinWidth="50"/>
                        </Grid.ColumnDefinitions>



                        <Label Grid.Column="0" FontFamily="Segoe WP" FontWeight="Bold" Margin="1,0,0,0" HorizontalContentAlignment="Left">SAVED SEARCHES</Label>
                        <Border BorderBrush="{StaticResource Application_BorderBrush}" BorderThickness="0,0,1,0" VerticalAlignment="Stretch" />
                        <ListBox x:Name="listBox_savedSearches" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="5,30,5,0" BorderThickness="0" ItemsSource="{Binding SavedSearches}" SelectedItem="{Binding SelectedSavedSearch}" ItemContainerStyle="{StaticResource ListBoxItemStyle_Metro}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <ListBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Delete" Command="{Binding DeleteSelectedSavedSearchCommand}"/>
                                </ContextMenu>
                            </ListBox.ContextMenu>
                        </ListBox>


                        <ListBox Grid.Column="2" FontSize="14" ItemsSource="{Binding Results}" BorderThickness="0"  Margin="5,0,0,0" ItemContainerStyle="{StaticResource ListBoxItemStyle_NoBackground}">
                            <ListBox.Resources>
                                <DataTemplate DataType="{x:Type core:Task}">
                                    <StackPanel Orientation="Horizontal" Height="24">
                                        <Label Foreground="LightGray" FontWeight="Bold"  HorizontalContentAlignment="Center" FontSize="14" Padding="0" ToolTip="Task" Width="20" Height="20" BorderThickness="1" BorderBrush="{StaticResource Application_BorderBrush}" FontFamily="Segoe WP" VerticalAlignment="Center" VerticalContentAlignment="Center">T</Label>
                                        <Button Margin="5,0,0,0" Command="{Binding ElementName=searchTab, Path=DataContext.ShowItemCommand}" CommandParameter="{Binding}" VerticalAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold" Style="{StaticResource ButtonStyle_Metro}">
                                            <Button.Content>
                                                <CheckBox IsChecked="{Binding Completed}" IsEnabled="False" Content="{Binding Content}"/>
                                            </Button.Content>
                                        </Button>
                                    </StackPanel>
                                </DataTemplate>
                                <DataTemplate DataType="{x:Type core:Project}">
                                    <StackPanel Orientation="Horizontal" Height="24">
                                        <Label Foreground="LightGray" FontWeight="Bold"  HorizontalContentAlignment="Center" FontSize="14" Padding="0" ToolTip="Project" Width="20" Height="20" BorderThickness="1" BorderBrush="{StaticResource Application_BorderBrush}" FontFamily="Segoe WP" VerticalAlignment="Center" VerticalContentAlignment="Center">P</Label>
                                        <Button Margin="5,0,0,0" Command="{Binding ElementName=searchTab, Path=DataContext.ShowItemCommand}" CommandParameter="{Binding}" Content="{Binding Name}" VerticalAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold" Style="{StaticResource ButtonStyle_Metro}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.Resources>
                        </ListBox>
                        
                        

                        <GridSplitter HorizontalAlignment="Right" Margin="-2,0,0,0" VerticalAlignment="Stretch" Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="5" Background="Transparent" DragCompleted="GridSplitter_DragCompleted"/>

                    </Grid>
                    
                    
                    
                    
                </Grid>
                
            </TabItem>
        </TabControl>
        
    </Grid>
</Page>
